package com.fancy.learncenter.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.andview.refreshview.XRefreshView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.FancyActivityDetailActivity;
import com.fancy.learncenter.activity.FancyMoveActivity;
import com.fancy.learncenter.activity.FancyVideoActivity;
import com.fancy.learncenter.activity.GalleryPicDetailActivity;
import com.fancy.learncenter.activity.GoodsDetailActivity;
import com.fancy.learncenter.activity.H5Activity;
import com.fancy.learncenter.activity.InviteActivity;
import com.fancy.learncenter.activity.InviteDetailActivity;
import com.fancy.learncenter.activity.LifeVideoDetailActivity;
import com.fancy.learncenter.activity.LoginActivity;
import com.fancy.learncenter.activity.MainActivity;
import com.fancy.learncenter.activity.MaterialActivity;
import com.fancy.learncenter.activity.MoreActivity;
import com.fancy.learncenter.activity.NewsH5Activity;
import com.fancy.learncenter.activity.PersonInfoActivity;
import com.fancy.learncenter.activity.ReleaseGraphicActivity;
import com.fancy.learncenter.activity.ReleaseHuoDongActivity;
import com.fancy.learncenter.activity.ReleasePeiXunActivity;
import com.fancy.learncenter.activity.ReleaseVideoActivity;
import com.fancy.learncenter.activity.ReleaseWenDaActivity;
import com.fancy.learncenter.activity.ReleaseXianZhiActivity;
import com.fancy.learncenter.activity.ReleaseZhiWeiActivity;
import com.fancy.learncenter.activity.ToothDetailsActivity;
import com.fancy.learncenter.activity.TopNewsActivity;
import com.fancy.learncenter.activity.TrainActivity;
import com.fancy.learncenter.activity.TrainApplyDetailActivity;
import com.fancy.learncenter.activity.TrainVideoDetailActivity;
import com.fancy.learncenter.activity.TzDetailActivity;
import com.fancy.learncenter.activity.UnusedGoodsActivity;
import com.fancy.learncenter.activity.VideoDetailActivity;
import com.fancy.learncenter.activity.YgtDetailDecActivity;
import com.fancy.learncenter.activity.YiGouTongActivity;
import com.fancy.learncenter.adapter.HomeAdapter;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.HomeDataBean;
import com.fancy.learncenter.bean.InviteDataBean;
import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.common.MyApplication;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.fancy.learncenter.utils.DimenUtil;
import com.fancy.learncenter.utils.LogUtil;
import com.fancy.learncenter.utils.SPUtils;
import com.fancy.learncenter.utils.ToastUtil;
import com.fancy.learncenter.utils.Utils;
import com.fancy.learncenter.utils.WXShareUtil;
import com.fancy.learncenter.view.CustomFootView;
import com.fancy.learncenter.view.CustomHeaderView;
import com.fancy.learncenter.view.LPopWindow;
import com.fancy.learncenter.view.PopupWindowShare;
import com.fancy.learncenter.view.RExLoopRecyclerView;
import com.fancy.learncenter.view.RLoopRecyclerView;
import com.fancy.learncenter.view.ScrollBanner;
import com.fancy.learncenter.view.TopBanner;
import com.fancy.learncenter.view.UPMarqueeView;
import com.fancy.learncenter.view.VerticalTextview;
import com.superservice.lya.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.rong.imageloader.utils.L;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends Fragment {

    View view;
    View topView;

    @Bind(R.id.xRefreshView)
    XRefreshView xRefreshView;
    @Bind(R.id.rootView)
    LinearLayout rootView;
    @Bind(R.id.recycleView)
    RecyclerView recycleView;

    RecyclerView inviteRecycleView;


    LinearLayout ic_yigoutong;
    LinearLayout ic_peixun;
    LinearLayout ic_invite;
    LinearLayout applyMore;
    LinearLayout trainMore;
    LinearLayout topNews;
    LinearLayout gengduo;


    LinearLayout unusedGoods;
    LinearLayout meterial;
    LinearLayout fancyMove;
    LinearLayout scroll_ll;
    RelativeLayout video_item;
    LinearLayout fancy_video;

    TextView video_title;

    SimpleDraweeView videoSimpleDraweeView;
    TopBanner topBanner;

    VerticalTextview noticeTitle;

    LinearLayout notice_ll;

    RExLoopRecyclerView scrollBanner;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home, container, false);
        ButterKnife.bind(this, view);
        topView = inflater.inflate(R.layout.fragment_home_top, container, false);
        initView();
        initInviteView();

        homeData();
        return view;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    private void initView() {

        notice_ll = (LinearLayout) topView.findViewById(R.id.notice_ll);
        gengduo = (LinearLayout) topView.findViewById(R.id.gengduo);
        gengduo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MoreActivity.class);
                startActivity(intent);
            }
        });


        ic_yigoutong = (LinearLayout) topView.findViewById(R.id.ic_yigoutong);
        ic_yigoutong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), YiGouTongActivity.class);
                startActivity(intent);
            }
        });
        noticeTitle = (VerticalTextview) topView.findViewById(R.id.notice_title);

        ic_peixun = (LinearLayout) topView.findViewById(R.id.ic_peixun);
        ic_peixun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), TrainActivity.class);
                startActivity(intent);
            }
        });

        videoSimpleDraweeView = topView.findViewById(R.id.simpleDraweeView);
        video_title = topView.findViewById(R.id.video_title);

        trainMore = (LinearLayout) topView.findViewById(R.id.trainMore);
        trainMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), TrainActivity.class);
                startActivity(intent);
            }
        });

        applyMore = (LinearLayout) topView.findViewById(R.id.applyMore);
        applyMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), InviteActivity.class);
                startActivity(intent);
            }
        });

        ic_invite = (LinearLayout) topView.findViewById(R.id.ic_invite);
        ic_invite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), InviteActivity.class);
                startActivity(intent);
            }
        });

        /**
         * 头条咨询
         */
        topNews = (LinearLayout) topView.findViewById(R.id.topNews);
        topNews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MaterialActivity.class);
                startActivity(intent);
            }
        });

        unusedGoods = topView.findViewById(R.id.unusedGoods);
        unusedGoods.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), UnusedGoodsActivity.class);
                startActivity(intent);
            }
        });

        video_item = topView.findViewById(R.id.video_item);

        meterial = topView.findViewById(R.id.meterial);
        meterial.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MaterialActivity.class);
                startActivity(intent);
            }
        });

        fancyMove = topView.findViewById(R.id.fancyMove);
        scroll_ll = topView.findViewById(R.id.scroll_ll);
        fancyMove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), FancyMoveActivity.class);
                startActivity(intent);
            }
        });

        fancy_video = topView.findViewById(R.id.fancy_video);
        fancy_video.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), FancyVideoActivity.class);
                startActivity(intent);
            }
        });

        scrollBanner = topView.findViewById(R.id.scrollBanner);

        topBanner = (TopBanner) topView.findViewById(R.id.guide);

        ViewGroup.LayoutParams para = topBanner.getLayoutParams();
        para.width = Utils.getScreenWidth(getActivity());
        para.height = (int) (Utils.getScreenWidth(getActivity()) / 1.77778);
        topBanner.setLayoutParams(para);


        topBanner.setBindViewCallBack(new TopBanner.BindViewCallBack<HomeDataBean.BannerArrBean>() {
            @Override
            public void bindView(View rootView, int position, final HomeDataBean.BannerArrBean itemData) {
                SimpleDraweeView simpleDraweeView = (SimpleDraweeView) rootView.findViewById(R.id.simpleDraweeView);
                simpleDraweeView.setImageURI(itemData.getImgsrc());

                rootView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//
                        if (!TextUtils.isEmpty(itemData.getLink())) {
                            Intent intent = new Intent(getActivity(), H5Activity.class);
                            intent.putExtra(H5Activity.URL_KEY, itemData.getLink());
                            startActivity(intent);
                        }

                    }
                });

            }
        });

        inviteRecycleView = (RecyclerView) topView.findViewById(R.id.inviteRecycleView);

        videoDatas = new ArrayList<>();

        xRefreshView.setPullRefreshEnable(true);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(linearLayoutManager);

        videoAdapter = new HomeAdapter(getActivity(), videoDatas);
        recycleView.setAdapter(videoAdapter);
        videoAdapter.setHeaderView(topView, recycleView);
        xRefreshView.disallowInterceptTouchEvent(true);
        xRefreshView.setCustomHeaderView(new CustomHeaderView(getActivity()));
        xRefreshView.setPinnedTime(1000);
        xRefreshView.setXRefreshViewListener(new XRefreshView.XRefreshViewListener() {
            @Override
            public void onRefresh() {
                LogUtil.MyLog("onLoadMore", "====onRefresh==");
                homeData();
            }

            @Override
            public void onRefresh(boolean isPullDown) {

            }

            @Override
            public void onLoadMore(boolean isSilence) {
                LogUtil.MyLog("onLoadMore", "====onLoadMore==");
            }

            @Override
            public void onRelease(float direction) {

            }

            @Override
            public void onHeaderMove(double headerMovePercent, int offsetY) {

            }
        });

    }

    HomeAdapter videoAdapter;


    ArrayList videoDatas;

    CommonRecycleViewAdapter<HomeDataBean.RecruitArrBean> inviteAdapter;

    private void initInviteView() {
        videoDatas = new ArrayList<>();
        xRefreshView.setPullRefreshEnable(false);
        GridLayoutManager linearLayoutManager = new GridLayoutManager(getActivity(), 4);
        inviteRecycleView.setLayoutManager(linearLayoutManager);
        inviteAdapter = new CommonRecycleViewAdapter<HomeDataBean.RecruitArrBean>(getActivity(), R.layout.fragment_home_invite_item, videoDatas) {
            @Override
            public void bindView(CustomViewHold customViewHold, final HomeDataBean.RecruitArrBean item, int position) {
                SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);


                simpleDraweeView.setImageURI(item.getCompany_logo());


                customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(mContext, InviteDetailActivity.class);
                        intent.putExtra("recruitId", item.getId());
                        mContext.startActivity(intent);
                    }
                });
            }
        };

        inviteRecycleView.setAdapter(inviteAdapter);

    }

    private void homeData() {
        Map map = new HashMap();

        HttpMehtod.getInstance().homeData(map, new IdeaObserver<BaseDataBean<HomeDataBean>>() {

            @Override
            public void onSuccess(final BaseDataBean<HomeDataBean> homeDataBeanBaseDataBean) {

                topBanner.setResData(homeDataBeanBaseDataBean.getData().getBanner_arr(), R.layout.banner_item);
                initNotice(homeDataBeanBaseDataBean);
                videoAdapter.notifyDataSetChanged((ArrayList<HomeDataBean.ToplineArrBean>) homeDataBeanBaseDataBean.getData().getTopline_arr());

                inviteAdapter.notifyDataSetChanged((ArrayList<HomeDataBean.RecruitArrBean>) homeDataBeanBaseDataBean.getData().getRecruit_arr());

                if (homeDataBeanBaseDataBean.getData().getVideo_arr() != null && homeDataBeanBaseDataBean.getData().getVideo_arr().size() > 0) {
                    videoSimpleDraweeView.setImageURI(homeDataBeanBaseDataBean.getData().getVideo_arr().get(0).getImgsrc());
                    video_title.setText(homeDataBeanBaseDataBean.getData().getVideo_arr().get(0).getTitle());
                    videoSimpleDraweeView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(getActivity(), TrainVideoDetailActivity.class);

                            intent.putExtra(VideoDetailActivity.VEDIO_KEY, homeDataBeanBaseDataBean.getData().getVideo_arr().get(0).getId());

                            getActivity().startActivity(intent);
                        }
                    });
                }
                if (homeDataBeanBaseDataBean.getData().getTrend_arr() != null) {
                    setView(homeDataBeanBaseDataBean.getData().getTrend_arr());
                } else {
                    scroll_ll.setVisibility(View.GONE);
                }


            }

            @Override
            public void onFail(int errorCode) {
                LogUtil.MyLog("login", "===login==onFail==" + errorCode);
            }
        });
    }

    private void initNotice(final BaseDataBean<HomeDataBean> homeDataBeanBaseDataBean) {

        if (!(homeDataBeanBaseDataBean.getData().getTopline_top() != null && homeDataBeanBaseDataBean.getData().getTopline_top().size() > 0)) {
            return;
        }
        notice_ll.setVisibility(View.VISIBLE);

        final ArrayList titleList = new ArrayList();

        for (int i = 0; i < homeDataBeanBaseDataBean.getData().getTopline_top().size(); i++) {

            titleList.add(homeDataBeanBaseDataBean.getData().getTopline_top().get(i).getTitle());
        }

        noticeTitle.setTextList(titleList);
        noticeTitle.setText(14, 5, getResources().getColor(R.color.font_color_black));//设置属性
        noticeTitle.setTextStillTime(3000);//设置停留时长间隔
        noticeTitle.setAnimTime(200);//设置进入和退出的时间间隔
        noticeTitle.setOnItemClickListener(new VerticalTextview.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {

                if (!TextUtils.isEmpty(homeDataBeanBaseDataBean.getData().getTopline_top().get(position).getUrl())) {
                    Intent intent = new Intent(getActivity(), NewsH5Activity.class);
                    intent.putExtra(H5Activity.URL_KEY, homeDataBeanBaseDataBean.getData().getTopline_top().get(position).getUrl());


                    intent.putExtra("topLineId", homeDataBeanBaseDataBean.getData().getTopline_top().get(position).getId());


                    startActivity(intent);

                }

//                        AdManagerUtils.goToAd(getActivity(), Constants.AppNotice, adDataBean.getAdvert().get(position));
            }
        });

        noticeTitle.startAutoScroll();
    }

    private void sign() {
        Map map = new HashMap();

        HttpMehtod.getInstance().sign(map, new IdeaObserver<BaseDataBean>() {
            @Override
            public void onSuccess(BaseDataBean stringBaseDataBean) {

                ToastUtil.show("签到成功");
            }

            @Override
            public void onFail(int errorCode) {

            }
        });
    }

    PopupWindowShare popupWindowShare;

    //分享弹出框
//    LPopWindow lPopWindow;

//    private void initPicPopWindow() {
//        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.pupopwinodw_share, null);
//        TextView cancel = (TextView) contentView.findViewById(R.id.cancel);
//        cancel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                lPopWindow.dismiss();
//            }
//        });
//        TextView weixin = (TextView) contentView.findViewById(R.id.weixin);
//        weixin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ToastUtil.show("微信");
//            }
//        });
//        TextView quan = (TextView) contentView.findViewById(R.id.quan);
//        quan.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ToastUtil.show("朋友圈");
//            }
//        });
//        lPopWindow = new LPopWindow.Builder(getActivity())
//                .setView(contentView)
//                .size(ViewGroup.LayoutParams.MATCH_PARENT, DimenUtil.dip2px(200))
//                .enableBackgroundDark(true) //弹出popWindow时，背景是否变暗
//                .setBgDarkAlpha(0.7f) // 控制亮度
//                .build();
//
//    }

    String shareUrlPic = "";
    String shareTitle = "邻牙";
    String shareContent = "邻牙 · 高效工作，轻松生活\n" +
            "汇聚30000+牙医，沟通洽谈、招聘求职、培训学习......上邻牙，更轻松。";
    String shareLinkUrl = "http://www.linya920.com/Nwx/download#";

    @OnClick({R.id.sign_tv, R.id.share_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.sign_tv:
                sign();
                break;
            case R.id.share_tv:
                if (popupWindowShare == null) {
                    popupWindowShare = new PopupWindowShare(getActivity(), recycleView);
                    popupWindowShare.setOnClickCallBack(new PopupWindowShare.OnClickCallBack() {
                        @Override
                        public void wxFriendCallBack() {
                            WXShareUtil.getInstance(getActivity()).shareWebPage(shareUrlPic, shareTitle, shareContent, shareLinkUrl, true);
                        }

                        @Override
                        public void wxCallBack() {
                            WXShareUtil.getInstance(getActivity()).shareWebPage(shareUrlPic, shareTitle, shareContent, shareLinkUrl, false);
                        }
                    });
                }
                popupWindowShare.showAtLocation();

                break;
        }
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);
        }
    }

    public class MyAdapter extends RLoopRecyclerView.LoopAdapter<MyViewHolder> {
        Context mContext;

        public MyAdapter(Context mContext) {
            this.mContext = mContext;
        }

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View inflate = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.fragment_home_top_item, parent, false);
            return new MyViewHolder(inflate);
        }

        @Override
        public void onBindLoopViewHolder(MyViewHolder holder, final int i) {
            LinearLayout content_ll = (LinearLayout) holder.itemView.findViewById(R.id.more_view);
//            //初始化布局的控件

            SimpleDraweeView simpleDraweeView = holder.itemView.findViewById(R.id.simpleDraweeView);
            simpleDraweeView.setImageURI(datas.get(i).getImgsrc());

            TextView name = holder.itemView.findViewById(R.id.name);
            name.setText(datas.get(i).getNick_name());

            TextView content = holder.itemView.findViewById(R.id.content);
            content.setText(datas.get(i).getContent());

            TextView time = holder.itemView.findViewById(R.id.time);
            time.setText(datas.get(i).getAdd_time());

            TextView submit = holder.itemView.findViewById(R.id.submit);

//            1贴子,2问答,3物品,4招聘,5培训,6活动,7小视频',


            if (datas.get(i).getType().equals("1")) {


                simpleDraweeView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), PersonInfoActivity.class);
                        intent.putExtra(PersonInfoActivity.USER_KEY, itemDatas.get(i).getUser_id());
                        startActivity(intent);
                    }
                });
                content_ll.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), TzDetailActivity.class);

                        intent.putExtra("wdListDataBean", itemDatas.get(i).getPublish_id());

                        startActivity(intent);
                    }
                });

                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent;
                        if (TextUtils.isEmpty(MyApplication.userId)) {
                            intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getActivity(), ReleaseGraphicActivity.class);
                            startActivity(intent);
                        }

                    }
                });
            } else if (itemDatas.get(i).getType().equals("2")) {


                simpleDraweeView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), PersonInfoActivity.class);
                        intent.putExtra(PersonInfoActivity.USER_KEY, datas.get(i).getUser_id());
                        startActivity(intent);
                    }
                });
                content_ll.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), ToothDetailsActivity.class);
                        intent.putExtra("wdListDataBean", datas.get(i).getPublish_id());
                        startActivity(intent);
                    }
                });

                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent;
                        if (TextUtils.isEmpty(MyApplication.userId)) {
                            intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getActivity(), ReleaseWenDaActivity.class);
                            startActivity(intent);
                        }

                    }
                });
            } else if (itemDatas.get(i).getType().equals("3")) {

                simpleDraweeView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), PersonInfoActivity.class);
                        intent.putExtra(PersonInfoActivity.USER_KEY, datas.get(i).getUser_id());
                        startActivity(intent);
                    }
                });
                content_ll.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        Intent intent = new Intent(getActivity(), GoodsDetailActivity.class);
                        intent.putExtra("GoodsDataBean", datas.get(i).getPublish_id() + "");
                        startActivity(intent);

                    }
                });


                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent;
                        if (TextUtils.isEmpty(MyApplication.userId)) {
                            intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getActivity(), ReleaseXianZhiActivity.class);
                            startActivity(intent);
                        }


                    }
                });
            } else if (itemDatas.get(i).getType().equals("4")) {

                simpleDraweeView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), PersonInfoActivity.class);
                        intent.putExtra(PersonInfoActivity.USER_KEY, datas.get(i).getUser_id());
                        startActivity(intent);
                    }
                });

                content_ll.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        Intent intent = new Intent(getActivity(), InviteDetailActivity.class);
                        intent.putExtra("recruitId", datas.get(i).getPublish_id());
                        startActivity(intent);

                    }
                });

                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent;
                        if (TextUtils.isEmpty(MyApplication.userId)) {
                            intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getActivity(), ReleaseZhiWeiActivity.class);
                            startActivity(intent);
                        }


                    }
                });
            } else if (itemDatas.get(i).getType().equals("5")) {
                simpleDraweeView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), PersonInfoActivity.class);
                        intent.putExtra(PersonInfoActivity.USER_KEY, datas.get(i).getUser_id());
                        startActivity(intent);
                    }
                });

                content_ll.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        Intent intent = new Intent(getActivity(), TrainApplyDetailActivity.class);
                        intent.putExtra("trainId", datas.get(i).getPublish_id());
                        startActivity(intent);


                    }
                });
                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent;
                        if (TextUtils.isEmpty(MyApplication.userId)) {
                            intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getActivity(), ReleasePeiXunActivity.class);
                            startActivity(intent);
                        }
                    }
                });
            } else if (datas.get(i).getType().equals("6")) {


                simpleDraweeView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), PersonInfoActivity.class);
                        intent.putExtra(PersonInfoActivity.USER_KEY, datas.get(i).getUser_id());
                        startActivity(intent);
                    }
                });
                content_ll.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent = new Intent(getActivity(), FancyActivityDetailActivity.class);
                        intent.putExtra("trainId", datas.get(i).getPublish_id());
                        startActivity(intent);

                    }
                });
                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        Intent intent;
                        if (TextUtils.isEmpty(MyApplication.userId)) {
                            intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getActivity(), ReleaseHuoDongActivity.class);
                            startActivity(intent);
                        }

                    }
                });
            } else if (datas.get(i).getType().equals("7")) {

                simpleDraweeView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), PersonInfoActivity.class);
                        intent.putExtra(PersonInfoActivity.USER_KEY, datas.get(i).getUser_id());
                        startActivity(intent);
                    }
                });
                content_ll.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        Intent intent = new Intent(getActivity(), LifeVideoDetailActivity.class);

                        intent.putExtra(VideoDetailActivity.VEDIO_KEY, datas.get(i).getPublish_id());

                        startActivity(intent);

                    }
                });

                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent;
                        if (TextUtils.isEmpty(MyApplication.userId)) {
                            intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getActivity(), ReleaseVideoActivity.class);
                            startActivity(intent);
                        }


                    }
                });
            }


        }

    }

    List<HomeDataBean.TrendArrBean> itemDatas;

    List<View> views = new ArrayList<>();

    /**
     * 初始化需要循环的View
     * 为了灵活的使用滚动的View，所以把滚动的内容让用户自定义
     * 假如滚动的是三条或者一条，或者是其他，只需要把对应的布局，和这个方法稍微改改就可以了，
     */
    private void setView(List<HomeDataBean.TrendArrBean> itemDatas) {

        this.itemDatas = itemDatas;


        MyAdapter myAdapter = new MyAdapter(getActivity());
        myAdapter.setDatas(itemDatas);
        scrollBanner.setAdapter(myAdapter);

    }


}
